﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using OPMS_V1.DOL;
using System.Data;

namespace OPMS_V1.BOL
{
    public class Advertisement
    {
        //Initializing the DOL Class associated with it.
        advertiseDOL objAdvertise=new advertiseDOL();

        /// <summary>
        /// Generates a random string with the given length
        /// </summary>
        /// <param name="size">Size of the string</param>
        /// <param name="lowerCase">If true, generate lowercase string</param>
        /// <returns>Random string</returns>
        #region Generate Random Task ID
        public string RandomString()
        {
            //Char array of Alphabets and numbers for generating the Task ID
            char[] pwdCharArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_".ToCharArray();
            Random rand = new Random();
            //Creating the Random TaskID of length between 20 and 30
            int tempSize = rand.Next(20, 30);
            StringBuilder RandStr = new StringBuilder(tempSize);

            for (int i = 0; i < tempSize; i++)
            {
                //Appending the TaskID to get the specified length
                RandStr.Append(pwdCharArray[rand.Next(0, pwdCharArray.Length)]);
            }
            //rweturn the TaskId
            return RandStr.ToString();
        }
        #endregion Generate Random Task ID


        /// <summary>
        /// This function is used for Random Property ID and returns to the Build.aspx.cs
        /// </summary>
        /// <returns></returns>
        #region Generate Random Property ID
        public string RandomProperty()
        {
            //Char array of numbers for generating the Property ID
            char[] pwdCharArray = "0123456789".ToCharArray();
            Random rand = new Random();
            //Creating the Random TaskID of length between 10 and 20
            int tempSize = rand.Next(8, 12);
            StringBuilder RandStr = new StringBuilder(tempSize);

            for (int i = 0; i < tempSize; i++)
            {
                //Appending the PropertyID to get the specified length
                RandStr.Append(pwdCharArray[rand.Next(0, pwdCharArray.Length)]);
            }
            //rweturn the PropertyId
            return RandStr.ToString();
        }
        #endregion Generate Random Property ID


        /// <summary>
        /// This function is used for Random LandLord ID and returns to the Build.aspx.cs
        /// </summary>
        /// <returns></returns>
        #region Generate Random LandLord ID
        public string RandomLandLordID()
        {
            //Char array of numbers for generating the LandLordID
            char[] pwdCharArray = "0123456789".ToCharArray();
            Random rand = new Random();
            //Creating the Random LandLordID of length between 10 and 20
            int tempSize = rand.Next(5, 10);
            StringBuilder RandStr = new StringBuilder(tempSize);

            for (int i = 0; i < tempSize; i++)
            {
                //Appending the LandLordId to get the specified length
                RandStr.Append(pwdCharArray[rand.Next(0, pwdCharArray.Length)]);
            }
            //rweturn the LandLordId
            return RandStr.ToString();
        }
        #endregion Generate Random LandLord ID


        /// <summary>
        /// This function is used for Random LandLord ID and returns to the Build.aspx.cs
        /// </summary>
        /// <returns></returns>
        #region Generate Random Inventory ID
        public string RandomInventoryID()
        {
            //Char array of numbers for generating the InventoryID
            char[] pwdCharArray = "0123456789".ToCharArray();
            Random rand = new Random();
            //Creating the Random LandLordID of length between 10 and 20
            int tempSize = rand.Next(5, 10);
            StringBuilder RandStr = new StringBuilder(tempSize);

            for (int i = 0; i < tempSize; i++)
            {
                //Appending the LandLordId to get the specified length
                RandStr.Append(pwdCharArray[rand.Next(0, pwdCharArray.Length)]);
            }
            //rweturn the LandLordId
            return RandStr.ToString();
        }
        #endregion Generate Random Inventory ID


        /// <summary>
        /// This function is used for checking the existance of the Task ID
        /// It returns the boolean condition whether the Task ID exists or Not
        /// </summary>
        /// <param name="TaskId"></param>
        /// <returns></returns>
        #region Checking existence of Task ID
        public Boolean checkTaskId(String TaskId) 
        {
            //Checking for the existence of the Task ID
            if (objAdvertise.checkTaskID(TaskId))
            {
                return true;
            }
                //If not found
            else
            {
                return false;
            }
        }
        #endregion Checking existence of Task ID


        /// <summary>
        /// This function is used for checking for existance of Property ID
        /// It returns the Boolean condition whether the Property ID exists or not
        /// </summary>
        /// <param name="randomProperty"></param>
        /// <returns></returns>
        #region Checking existence of Property ID
        public Boolean checkPropertyId(String randomProperty)
        {
            //Checking if the property ID Exists
            if (objAdvertise.checkPropertyId(randomProperty))
            {
                return true;
            }
            else
            {//If not exists
                return false;
            }
        }
        #endregion Checking existence of Property ID


        /// <summary>
        /// This function is used for checking for existance of LandLordID
        /// It returns the Boolean condition whether the LandLordID exists or not
        /// </summary>
        /// <param name="randomProperty"></param>
        /// <returns></returns>
        #region Checking existence of LandLordID
        public Boolean checkLandLordID(String randomLandLordID)
        {
            //Whether the LandLordID exists or not
            if (objAdvertise.checkLandLordID(randomLandLordID))
            {
                return true;
            }
            else
            {//If not exists
                return false;
            }
        }
        #endregion Checking existence of LandLordID


        /// <summary>
        /// This function is used for checking for existance of LandLordID
        /// It returns the Boolean condition whether the LandLordID exists or not
        /// </summary>
        /// <param name="randomProperty"></param>
        /// <returns></returns>
        #region Checking existence of InventoryID
        public Boolean checkInventoryID(String InventoryID)
        {
            //Whether the LandLordID exists or not
            if (objAdvertise.checkInventoryID(InventoryID))
            {
                return true;
            }
            else
            {//If not exists
                return false;
            }
        }
        #endregion Checking existence of InventoryID

        /// <summary>
        /// This function is used for Updating the PDetails if the Landlord records already exists.
        /// It updates the information such as FName, LName, sex, dob etc.
        /// </summary>
        /// <param name="fName"></param>
        /// <param name="lName"></param>
        /// <param name="sex"></param>
        /// <param name="dob"></param>
        /// <param name="phone"></param>
        /// <param name="streetnum"></param>
        /// <param name="streetName"></param>
        /// <param name="postCode"></param>
        /// <param name="area"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public DataSet UpdatePDetails(string fName, string lName, string sex, string dob, string phone, string streetnum, string streetName, string postCode, string area, string state, string LandLordID)
        {
            //Pass on the information to Update the records.
            DataSet condition = objAdvertise.UpdatePDetails(fName, lName, sex, dob, phone, streetnum, streetName, postCode, area, state, LandLordID);
            return condition;
        }

        /// <summary>
        /// This function is used for getting teh States for the Property
        /// </summary>
        /// <returns></returns>
        public DataSet GetStates()
        {
            //Getting the States into DataSet (Collection)
            DataSet condition = objAdvertise.GetStates();
            return condition;
        }

        /// <summary>
        /// This function is used for getting the AreaID for the Area, PostCode, State
        /// </summary>
        /// <param name="Area"></param>
        /// <param name="PostCode"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public string GetAreaID(string Area, string PostCode, string state)
        {
            //Getting the AreaID while passing Area, PostCode, state
            string AreaId = objAdvertise.GetAreaID(Area, PostCode, state);
            return AreaId;
        }

        /// <summary>
        /// This function is used for checking the Address in the database
        /// for its existance.
        /// So, If the user types in wrong address, it wont let the user to proceed
        /// </summary>
        /// <param name="Area"></param>
        /// <param name="postalCode"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int CheckAddress(string Area, string postalCode, string state)
        {
            int condition;
            //Returning the Boolean value of the Result
            condition = objAdvertise.CheckAddress(Area, postalCode,state);
            return condition;
        }

        /// <summary>
        /// This function is used for getting the Personal Details of the LandLord
        /// </summary>
        /// <param name="accountname"></param>
        /// <returns></returns>
        public DataSet Get_PDetails(string accountname)
        {
            //Getting the collection of personal Details for the LandLord
            DataSet PDetails = objAdvertise.Get_PDetails(accountname);
            return PDetails;
        }

        /// <summary>
        /// This function is used for Getting the Inventory ID for the Property
        /// </summary>
        /// <param name="PropertyID"></param>
        /// <returns></returns>
        public DataSet Get_InventoryID(string PropertyID)
        {
            //Returning the Inventory ID for the Property
            DataSet InventoryID = objAdvertise.Get_InventoryID(PropertyID);
            return InventoryID;
        }
        
    }
}
